<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-arrow-left"></i> <span @click="pushList">返回</span>
                </el-breadcrumb-item>
                <el-breadcrumb-item>订单信息</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="form-box">
                <el-form ref="form" :model="bo" label-width="80px">
                    <el-form-item label="客户名称">
                        <el-input @blur="verifyName" v-model="bo.userName"></el-input>
                    </el-form-item>
                    <el-form-item label="订单状态">
                        <el-select v-model="bo.start" placeholder="请选择">
                            <el-option label="待审核" value="0"></el-option>
                            <el-option  label="已完成" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="仓库">
                        <el-select v-model="bo.warehouseId" placeholder="请选择">
                            <el-option  label="1" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="发货日期">
                            <el-date-picker
                                    type="date"
                                    placeholder="选择日期"
                                    v-model="bo.deliveryTime"
                                    value-format="yyyy-MM-dd"
                                    style="width: 100%;"
                            ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="下单时间">
                        <el-date-picker
                                type="date"
                                placeholder="选择日期"
                                v-model="bo.orderTime"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="text" @click="handleSubmit">批量添加商品</el-button>
                        <el-dialog
                                title="商品信息"
                                :visible.sync="dialogVisible"
                                width="80%">
                            <el-table
                                    ref="multipleTable"
                                    :data="tableData"
                                    tooltip-effect="dark"
                                    style="width: 100%"
                                    @selection-change="handleSelectionChange">
                                <el-table-column
                                        type="selection"
                                        width="55">
                                </el-table-column>
                                <el-table-column
                                        prop="prodectDetailsId"
                                        label="序号"
                                        width="120">
                                </el-table-column>
                                <el-table-column
                                        prop="prodectDetailsName"
                                        label="商品名"
                                        width="120">
                                </el-table-column>
                                <el-table-column
                                        prop="price"
                                        label="商品单价"
                                        width="120">
                                </el-table-column>
                                <el-table-column
                                        prop="prodectTypeDetailsName"
                                        label="商品类型"
                                        width="120">
                                </el-table-column>
                                <el-table-column
                                        label="下单数量"
                                        width="120">
                                    <template slot-scope="scope">
                                        <el-input v-model="scope.row.orderQuantity=''" placeholder="请输入内容"></el-input>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-dialog>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">表单提交</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "addOrder",
        data() {
            return {
                dialogVisible: false,
                tableData: [],
                bo:{
                    warehouseId:0,
                    start:'',
                    orderTime:'',
                    deliveryTime:'',
                    userName: '',
                    userId:0,
                    details:[]
                }
            };
        },
        methods: {
            handleSubmit(){
                this.dialogVisible= true;
                this.$axios.get("ORDER-SERVICE/prodect/prodectlist").then( result=>{
                    this.tableData=result.data.data;
                    console.log(this.tableData);
                });
            },
            pushList(){
                this.$router.push('/order');
            },
            handleSelectionChange(val) {
                console.log(val);
             this.bo.details=val;
            },
            verifyName(){
                this.$axios.get("ORDER-SERVICE/user/verifyName?userName="+this.bo.userName,).then( result=>{
                    this.bo.userId=result.data.data;
                    console.log(this.bo.userId);
                });
            },
            onSubmit() {
                this.$axios.post("ORDER-SERVICE/order/add",this.bo).then( result=>{
                   console.log(result.data);
                    this.$message.success('提交成功！');
                    this.$router.push('/order')
                });


            }
        }
    }
</script>

<style scoped>

</style>